/**
 * @author wcj
 * @Date 2021/6/1 13:09
 * @Version 1.0
 */
public class JvmStackOOM {

 private void dontStop() {
  while (true) {
  }
 }

 public void stackLeakByThread() {
  while (true) {
   Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
     dontStop();
    }
   });
   thread.start();
  }
 }

 /***
  * 不停的创建线程，每个线程都会分配虚拟机栈和本地方法栈，当无法分配的时候，就会出现OOM异常
  * @param args
  */
 public static void main(String[] args) {
  JvmStackOOM jvmStackOOM = new JvmStackOOM();
  jvmStackOOM.stackLeakByThread();
 }
}


